#include "dialogaddobject.h"
#include "ui_dialogaddobject.h"
#include <QFileDialog>

DialogAddObject::DialogAddObject(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogAddObject)
{
    ui->setupUi(this);


}

DialogAddObject::~DialogAddObject()
{
    delete ui;
}

void DialogAddObject::on_buttonBox_accepted(){
    ok = true;
    if(ui->radioSphere->isChecked()) type = SPHERE;
    else if(ui->radioBox->isChecked()) type = BOX;
    else if(ui->radioTriMesh->isChecked()) type = TRIMESH;
    else {
        ok = false;
        type = NO;
        return;
    }

    switch(type)
    {
        case SPHERE:
                  radius = ui->editRadius->text().toFloat(&ok); break;
        case BOX: sizeBox.x(ui->editSizeX->text().toFloat(&ok));
                  sizeBox.y(ui->editSizeY->text().toFloat(&ok));
                  sizeBox.z(ui->editSizeZ->text().toFloat(&ok));
                  break;
        case TRIMESH: filename = ui->editFilename->text(); break;
    }
}

void DialogAddObject::on_buttonSelectFile_clicked()
{
#ifdef Q_WS_MAC
    QString filename = QFileDialog::getOpenFileName(NULL, "Select Mesh","../../../../../svn/meshes/",tr("Mesh Files (*.obj *.off)"));
#else
    QString filename = QFileDialog::getOpenFileName(NULL, "Select Mesh",QDir::currentPath(),tr("Mesh Files (*.obj *.off)"));
#endif
    if(filename == "")
        return;
    ui->editFilename->setText(filename);
}
